Hi
// Overloading existing 'fileExists_' (other return value and parameters)
string fileExists_(string sFile, bool &b)
{
return("")
}
// Try using original 'fileExists_'
bool b = fileExists_("hello")
print b
a_vestlin - Mon May 10 06:54:43 EDT 2010 |
Re: Overloading functions in the global context Maybe I should add that I get the following error message: -E- DXL: <Line:8> incorrect use of identifier (fileExists_) -I- DXL: all done with 1 error and 0 warnings |
Re: Overloading functions in the global context a_vestlin - Mon May 10 07:01:37 EDT 2010 Maybe I should add that I get the following error message: -E- DXL: <Line:8> incorrect use of identifier (fileExists_) -I- DXL: all done with 1 error and 0 warnings
Because you aren't using the overloaded function properly?
string fileExists_(string sFile, bool &b)
{
b = true
return("")
}
// Try using original 'fileExists_'
bool b
fileExists_("hello", b)
print b
|
Re: Overloading functions in the global context kbmurphy - Mon May 10 12:51:06 EDT 2010
Because you aren't using the overloaded function properly?
string fileExists_(string sFile, bool &b)
{
b = true
return("")
}
// Try using original 'fileExists_'
bool b
fileExists_("hello", b)
print b
No, my point is that I cannot use the original function (if it is declared in the global context) after
// Redefine original 'fileExists_'
bool fileExists_(string sFile)
{
Stat st
bool b
st = create(sFile)
if ( !null(st) )
{
delete(st)
return(true)
}
return(false)
}
string fileExists_(string sFile, bool &b)
{
b = true
return("")
}
// Try using redefined original 'fileExists_'
bool b
b = fileExists_("hello")
print b
// Try using original 'fileExists_' without any overloading
bool b
b = fileExists_("hello")
print b
|
Re: Overloading functions in the global context a_vestlin - Tue May 11 02:24:22 EDT 2010
No, my point is that I cannot use the original function (if it is declared in the global context) after
// Redefine original 'fileExists_'
bool fileExists_(string sFile)
{
Stat st
bool b
st = create(sFile)
if ( !null(st) )
{
delete(st)
return(true)
}
return(false)
}
string fileExists_(string sFile, bool &b)
{
b = true
return("")
}
// Try using redefined original 'fileExists_'
bool b
b = fileExists_("hello")
print b
// Try using original 'fileExists_' without any overloading
bool b
b = fileExists_("hello")
print b
So obviously the parser will lookup symbols in the current context first and not search the top level context when it finds the symbol. Thats bad. Anyway you can get around it, by hooking the function in the current context before redeclaring it:
// "hook" the function in the current context before overriding it ...
bool fileExistsOld (string file) { return fileExists_ file }
// override it
bool fileExists_ (string file, bool b) { /* some code */ }
string s = "c:\\test.dxl"
print (fileExistsOld s) "\n"
print (fileExists_ (s, true)) "\n"
Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS
|